package com.example.server.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 日期转换
 */
@Component
public class DateConverter implements Converter<String, LocalDate> {
    @Override
    public LocalDate convert(String source) {
        // 添加空值检查
        if (source == null || source.trim().isEmpty()) {
            return null; // 或者返回默认日期
        }
        try{
        return LocalDate.parse(source,DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }catch (Exception e){
           e.printStackTrace();
        }
        return null;
    }
}
